package main

import (
	rxgo "RxGO"
	"fmt"
	"time"
)

func main() {
	// filter
	in := rxgo.From([]interface{}{1, 2, 3, 4})
	out := rxgo.Filter(in, func(i interface{}) bool {
		num := i.(int)
		return num%2 == 0
	})
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// distinct
	in = rxgo.From([]interface{}{1, 2, 2, 3, 3, 5})
	out = rxgo.Distinct(in)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// ElementAt
	out = rxgo.ElementAt(rxgo.From([]interface{}{0, 1, 2, 3}), 2)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// Skip
	in = rxgo.From([]interface{}{1, 2, 3, 4})
	out = rxgo.Skip(in, 2)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// Reduce
	in = rxgo.From([]interface{}{1, 2, 3, 4})
	out = rxgo.Reduce(in, func(i interface{}, i2 interface{}) interface{} {
		return i.(int) + i2.(int)
	}, 0)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// Merge
	c1 := rxgo.From([]interface{}{1, 2, 9})
	c2 := rxgo.From([]interface{}{3, 4, 10})
	c3 := rxgo.From([]interface{}{5, 7, 11})
	c4 := rxgo.From([]interface{}{6, 8, 12})
	ch := rxgo.Merge(c1, c2, c3, c4)
	for i := range ch {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// Debounce
	in = rxgo.IntervalRange(0, 4, 40*time.Millisecond, 0)
	out = rxgo.Debounce(in, time.Millisecond*100)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// First
	out = rxgo.First(rxgo.From([]interface{}{0, 1, 2, 3}))
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// Last
	out = rxgo.Last(rxgo.From([]interface{}{1, 2, 3}))
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// IgnoreElements
	out = rxgo.IgnoreElements(rxgo.From([]interface{}{1, 2, 3}))
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// Sample
	in = rxgo.IntervalRange(1, 7, time.Millisecond*30, 0)
	out = rxgo.Sample(in, time.Millisecond*50)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// SkipLast
	in = rxgo.From([]interface{}{1, 2, 3, 4})
	out = rxgo.SkipLast(in, 2)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// Take
	in = rxgo.From([]interface{}{1, 2, 3, 4})
	out = rxgo.Take(in, 2)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// TakeLast
	in = rxgo.From([]interface{}{1, 2, 3, 4})
	out = rxgo.TakeLast(in, 2)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()
	// StartWith
	in = rxgo.From([]interface{}{3, 4})
	out = rxgo.StartWith(in, 1, 2)
	for i := range out {
		fmt.Print(i)
		fmt.Print(" ")
	}
	fmt.Println()

	// to find more function of the rxgo, see the code in ./RxGO,
	// expecially in operator_test.go which can tell how to use the function
}
